home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-03-08 | 9.0 KB | 432 lines | [TEXT/ALFA] |
- #==============================================================================
- proc normalLeftBracket {} {
- insertText "\{"
- }
- proc normalRightBracket {} {
- insertText "\}"
- }
- bind '\[' <zs> normalLeftBracket
- bind '\]' <zs> normalRightBracket
- #==============================================================================
-
-
- # Select the next or current word. If word already selected, will go to next.
- proc hiliteWord {} {
- if {[getPos]!=[selEnd]} forwardChar
- forwardWord
- set start [getPos]
- backwardWord
- select $start [getPos]
- }
-
- bind 'h' <z> hiliteWord
-
- # For mark stack.
- set markName 0
- set markStack ""
-
-
- #=============================================================================
- # Hook procs recognized: "openHook", "closeHook", "activateHook", "deactivateHook",
- # "suspendHook", "saveasHook", "saveHook", and "resumeHook".
- #=============================================================================
-
- # Event hooks - set specific modes when files opened.
- proc openHook name {
- global winModes
- $winModes($name)
- if {$name == {*Toolserver shell*}} startMPW
- addWinName $name
- }
-
- # full pathname
- proc saveHook name {
- global backup
- if ($backup) {
- catch {rm $name~}
- cp $name $name~
- }
- }
-
- # Clean up the mark stack.
- proc closeHook name {
- global markStack
- global winModes
- unset winModes($name)
- if [llength $markStack] {
- set markStack [removePat $markStack $name*]
- }
- removeWinName $name
- }
-
- proc saveasHook {oldName newName} {
- global winModes
- removeWinName $oldName
- addWinName $newName
- setWinMode $newName
- $winModes($newName)
- }
-
-
- proc activateHook name {
- global winModes
- if {[catch {$winModes($name)}]} {
- setWinMode $name
- $winModes($name)
- }
- }
-
-
- set winModes("") ""
-
- proc setWinMode name {
- global winModes
- set nm [file tail $name]
- case $name in {
- "*.c" { set winModes($name) setCMode }
- "*.tex" { set winModes($name) setTexMode; winFuncTitle $nm "Sect" }
- "*.cc" { set winModes($name) setC++Mode; winFuncTitle $nm "Meth" }
- "*.cp" { set winModes($name) setC++Mode; winFuncTitle $nm "Meth" }
- "*.C" { set winModes($name) setC++Mode; winFuncTitle $nm "Meth" }
- "*.h" { set winModes($name) setCMode }
- "*.f" { set winModes($name) setFortranMode }
- "*.tcl" { set winModes($name) setTclMode; winFuncTitle $nm "Proc" }
- {*Toolserver\ sh*} { set winModes($name) setMPWMode; winFuncTitle $nm "Proc" }
- {*tcl\ sh*} { set winModes($name) setShellMode; winFuncTitle $nm "Proc" }
- "*.sty" { set winModes($name) setTexMode; winFuncTitle $nm "Sect" }
- "Browser" { set winModes($name) setBrowseMode }
- default { set winModes($name) setTextMode }
- }
- }
-
-
- # 'modes' is inspected by alpha for the popup mode menu. 'newMode' is
- # called by Alpha in case of a successful choice.
- set modes { C C++ Csh Fort MPW Tcl TeX Text }
-
- set modeProcs(C) setCMode
- set modeProcs(C++) setC++Mode
- set modeProcs(Csh) setShellMode
- set modeProcs(Fort) setFortranMode
- set modeProcs(MPW) setMPWMode
- set modeProcs(Tcl) setTclMode
- set modeProcs(TeX) setTexMode
- set modeProcs(Text) setTextMode
-
- proc newMode mode {
- global winModes
- global modeProcs
-
- set name [lindex [winNames -f] 0]
- $modeProcs($mode)
- set winModes($name) $modeProcs($mode)
- }
-
-
- proc deactivateHook name {
- }
-
- proc suspendHook name {
- global iconifyOnSwitch
- global suspIconed
- if {$iconifyOnSwitch} {
- set wins [winNames -f]
- foreach win $wins {
- if {![icon -f "$win" -q]} {
- set suspIconed($win) 1
- icon -f "$win" -t
- }
- }
- }
- }
-
- proc resumeHook name {
- global iconifyOnSwitch resumeRevert suspIconed
- if {$iconifyOnSwitch && [info exists suspIconed]} {
- set wins [winNames -f]
- foreach win [array names suspIconed] {
- icon -f "$win" -o
- }
- unset suspIconed
- }
- if {$resumeRevert} {
- set resumeRevert 0
- revert
- }
- }
-
- # Handles dynamically adding and deleting window names from menu.
- proc addWinName name {
- global winNameToNum
- global winNumToName
- global fullNames
-
- for {set i 0} {$i<100} {incr i} {
- if {[catch {set nm $winNumToName($i)} res] == "1"} {
- if {$fullNames != "0"} {
- set nm $name
- } else {
- regexp {[^:]*$} $name nm
- }
- if {$i < 10} {
- addMenuItem -m -l "/$i" Wins $nm
- } else {
- addMenuItem -m -l "" Wins $nm
- }
- set winNumToName($i) $name
- set winNameToNum($name) $i
- return
- }
- }
- }
-
- proc removeWinName name {
- global winNameToNum
- global winNumToName
- global fullNames
-
- set num $winNameToNum($name)
- unset winNumToName($num)
- unset winNameToNum($name)
- if {$fullNames == "1"} {
- deleteMenuItem -m Wins $name
- } else {
- regexp {[^:]*$} $name nm
- deleteMenuItem -m Wins $nm
- }
- }
-
-
- proc menuWin {menu name} {
- global winNameToNum
-
- set nms [array names winNameToNum]
- foreach nm $nms {
- if {[string match *$name $nm] == "1"} {
- bringToFront $name
- if [icon -q] { icon -f $name -o }
- return
- }
- }
- return "normal"
- }
-
-
- set lastMode 0
-
- # rta Creating texWasLast variable
- set texWasLast 0
- # rta Following changed from ThinkC to MPW
-
-
- # Modes
-
- # Fortran programming mode
- proc setFortranMode {} {
- changeMode "Fort"
- uplevel #0 {
- set elecLBrace 0
- set elecRBrace 0
- set electricSemi 0
- set wordWrap 0
- set funcExpr {^( |\t)(subroutine|.*function|SUBROUTINE|.*FUNCTION).*\(.*$}
- set sortedIsDefault 0
- }
- }
-
-
- # Ordinary, default mode
- proc setTextMode {} {
- changeMode "Text"
- uplevel #0 {
- set elecLBrace 0
- set elecRBrace 0
- set electricSemi 0
- set wordWrap 1
- set prefixString "> "
- set suffixString " <--"
- }
- }
-
-
- #================================================================================
-
- # Instantiate a global variable to the path of a file (usually an app). As a
- # side-effect, make the instantiation permanent by adding a line to 'definitions.tcl'.
- proc addAppPath {name var} {
- global $var
-
- if {[catch {getfile "Find '$name' app:"} path]} {return 1}
- set $var $path
-
- addUserLine "set $var \"[quoteExpr2 $path]\""
- return 0
- }
-
- proc addUserLine {line} {
- global HOME
-
- if {[file exists "$HOME:userStartup.tcl"]} {
- set fid [open "$HOME:userStartup.tcl" "a"]
- } else {
- set fid [open "$HOME:userStartup.tcl" "w"]
- }
- puts $fid $line
- close $fid
- }
-
-
- proc getFileSig {f} {
- catch {lindex [ls -l $f] 5} var
- return $var
- }
-
-
- # Look for given app sig in active processes. If not there, try to
- # launch with 'path' prompting for 'path' if necessary.
- # Return the real name of the app. Don't switch.
- proc checkRunning {name sig path} {
- global $path
- foreach proc [processes] {
- if {[lindex $proc 1] == $sig} {
- return [lindex $proc 0]
- }
- }
- if {![file exists [set $path]]} {
- alertnote "'[set $path]' does not exist!"
- error ""
- }
- if {[catch {getFileSig [set $path]}]} {
- if {[addAppPath $name $path]} return
- }
- set sig [getFileSig [set $path]]
- if {[catch {launch -f [set $path]}]} {
- error "Problem with script."
- }
- return [file tail [set $path]]
- # return [checkRunning $name $sig $path]
- }
-
- #================================================================================
- # Excalibur is the only Mac spell-checker that I know of which will handle LaTex as
- # well as ordinary text.
-
- set excaliburMenu "•128"
-
- proc spellcheckWindow {} {
- global excaliburPath resumeRevert
-
- catch {checkRunning Excalibur XCLB excaliburPath} name
-
- if {[winInfo dirty]} {
- if {[askyesno "Save '[lindex [winNames] 0]'?"] == "yes"} {
- save
- }
- }
- if {[catch {sendOpenEvent -n $name [lindex [winNames -f] 0]}] } {
- beep
- } else {
- switchTo $name
- }
- set resumeRevert 1
- }
-
- proc spellcheckSelection {} {
- global excaliburPath
-
- catch {checkRunning Excalibur XCLB excaliburPath} name
-
- if {[getPos] == [selEnd]} {
- beep
- message "No selection"
- return;
- }
- copy
- switchTo $name
- }
-
- menu -n $excaliburMenu {
- "spellcheckWindow"
- }
- insertMenu $excaliburMenu
-
- #================================================================================
-
-
- proc changeMode {newMode} {
- global lastMode
- global savedIsMeta
- global wordBreak
- global wordBreakPreface
- global optionIsMeta
- global latexMenu excaliburMenu thinkMenu toolserverMenu
-
- displayMode $newMode
- if {$lastMode == $newMode} return
-
- case $lastMode in {
- "Tex" {
- set optionIsMeta $savedIsMeta
- set wordBreakPreface {[^a-zA-Z0-9_]}
- set wordBreak {[a-zA-Z0-9_]+}
- set optionIsMeta 1
- catch {removeMenu $latexMenu}
- insertMenu $excaliburMenu
- }
- "Csh" {
- catch {removeMenu "Tcl"}
- }
- "Tcl" {
- catch {removeMenu "Tcl"}
- }
- "BRWZ" {
- catch {removeMenu "Browse"}
- }
- "C" {
- catch {removeMenu $thinkMenu}
- catch {removeMenu $toolserverMenu}
- }
- "C++" {
- catch {removeMenu $thinkMenu}
- catch {removeMenu $toolserverMenu}
- }
- }
- global mode
- set mode $newMode
- set lastMode $newMode
- }
-
-
- proc alphaHelp {} {
- global HOME
- edit -r -m "$HOME:Help:General Help"
- }
-
-
- set patternLibrary {
- { "Pascal to C Comments" {\{([^\}]*)\}} {/* \1 */} }
- { "C++ to C Comments" {//(.*)} {/* \1 */}}
- }
-
-
- proc dividingLine {} {
- insertText "================================================================================\r"
- }
- bind 'l' <C> dividingLine
-
-
- #================================================================================
-
- if {[catch {info args oldCd}]} {
- rename cd oldCd
- }
-
- proc cd args {
- global HOME
- if {[llength $args]} {
- oldCd [string trim [eval list $args] "\{\}"]
- } else {
- oldCd $HOME
- }
- }
-